const Controller = require('../../core/controller/ApiController');
const {Route, HttpGet, Middleware, filters} = require('../../../plugin/egg-decorator-router/lib');
const {ExceptionHandler} = require('../../../plugin/egg-controller-exception-handler/lib');

@Route('/api/admin/dataany')
class DataCtrl extends Controller {

    //数据分析/服务对象统计
    @HttpGet('/svcobj')
    @ExceptionHandler()
    async serviceObj() {
        const rule = {
            community_id: 'int',
            subdistrict_id: 'int',
        };
        this.validate(rule, this.ctx.request.query);
        const obj = this.ctx.request.query;
        this.result.data = await this.service.admin.dataany.main.serviceObj(obj.community_id, obj.subdistrict_id);
    }

    //获取服务人员列表
    @HttpGet('/svcstaff/list')
    @ExceptionHandler()
    async getStaffList() {
        this.result.data = await this.service.admin.dataany.main.getStaffList(this.ctx.session.town_id);
        return '查询成功'
    }

    //服务项目分析
    @HttpGet('/svcitem')
    @ExceptionHandler()
    async analyzeSvcItem() {
        const rule = {
            begin: 'anyDate',
            end: 'anyDate',
            svc_staff_id: 'int'
        };
        this.validate(rule, this.ctx.request.query);
        const query = this.ctx.request.query;
        this.result.data = await this.service.admin.dataany.main.analyzeSvcItem(query.begin, query.end, query.svc_staff_id);
        return '查询成功'
    }
}

module.exports = DataCtrl;
